/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.system.renovation.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.system.renovation.dao.IApprovalItemConfigDao;
import com.ce.pms.system.renovation.model.ApprovalItemConfigDO;
import com.sitechasia.webx.core.support.Page;



/**
 * 功能描述：<br>
 * @author 易贤建 创建日期：2008-12-29<br>
 */
public class ApprovalItemConfigDaoImpl extends PmsBaseDaoImpl<ApprovalItemConfigDO> implements IApprovalItemConfigDao{

	public ApprovalItemConfigDO findApprovalItemConfigByID(Long keyword){
		String queryStr = "FROM ApprovalItemConfigDO appDO  WHERE appDO.keyword=?";
		Query query = super.createQuery(queryStr, new Object[]{keyword});
		return (ApprovalItemConfigDO)query.uniqueResult();
	}
	/**
	 * 功能描述:通过ID查询DO<br>
	 * @param keyword
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2009-1-4  <br>
	 */
	public List<ApprovalItemConfigDO> findApprovalItemConfigByItemName(String itemName){
		String queryStr = "FROM ApprovalItemConfigDO appDO  WHERE appDO.itemName=?";
		Query query = super.createQuery(queryStr, new Object[]{itemName});
		return query.list();
	}
	/**
	 * 功能描述:keyword不同,ItemName一样的DO<br>
	 * @param keyword
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2009-1-4  <br>
	 */
	public List<ApprovalItemConfigDO> findByItemNameWithoutKeyword(Long keyword,String itemName){
		StringBuffer queryStr = new StringBuffer("FROM ApprovalItemConfigDO appDO  ");
					  queryStr.append(" WHERE 1=1 AND appDO.keyword!=?");
					  queryStr.append(" AND appDO.itemName=? ");
		Query query = super.createQuery(queryStr.toString(), new Object[]{keyword,itemName});
		return query.list();
	}
	/**
	 * 分页查询DO
	 */
	public Page queryApprovalItemList(SearchVO searchVO) {
		String queryStr = "FROM ApprovalItemConfigDO appDO  WHERE appDO.state='001' ORDER BY appDO.sysInfo.sysDate DESC";
		return super.pagedQueryByPageNo(queryStr, searchVO.getPageNo(), searchVO.getPageSize());
	}
	/**
	 * 功能描述:查询指定员工的所有审批项目<br>
	 * @param employeeId
	 * @return<br>
	 * Create author:易贤建<br>
	 * Create on:2008-12-31<br>
	 */
	public List<ApprovalItemConfigDO> getItemConfigs(Long employeeId) {
		StringBuffer queryStr = new StringBuffer("select appDO FROM ApprovalItemConfigDO appDO join appDO.approvallers empl ");
					 queryStr.append("WHERE 1 =1 ");
					 queryStr.append(" AND empl.employeeId=?");
	    Query query = super.createQuery(queryStr.toString(), new Object[]{employeeId});

		return query.list();
	}
}
